< previous page page_262 next page >

Page 262
At this point, you have a way to determine which points in the first image correspond to which points in the second image. It is still not completely obvious how to use that mapping to morph the images.
Use tweening techniques to smoothly convert the points in the first grid into the points in the second. For each of these tweens, consider the pixels in the intermediate image. Use the quadrilateral mapping techniques to find the corresponding points in the two key images. Finally, use linear interpolation to pick the intermediate pixel's color. For example, if the tween is one-quarter of the distance between the first and second key frame, make the intermediate pixel one-quarter of the color of the first image's pixel plus three-quarters of the second image's pixel.
Notice that this process contains two interpolation steps: transforming the starting grid into the ending grid and blending the colors of the starting and ending images.
Example program Morph, shown in Figures 9.10 and 9.11, uses this technique to create morphing animation sequences. Figure 9.10 shows the program's transformation grids. Click and drag on the grid points to make corresponding features in the two images line up. For example, in Figure 9.10, corresponding grid points mark the images' eyes, noses, cheeks, ears, and so forth.
Figure 9.11 shows program Morph after it has created 20 out of 30 tweens. The calculations required to create each tween are fairly complex, so the whole process can take a while. The program took 11 minutes to generate 30 tweens for the images shown in Figures 9.10 and 9.11.
Specialized Animation
The previous sections of this chapter explain some of the ways you can create and display images to produce the illusion of motion. You can use these techniques to add animation to almost any kind of Visual Basic program. The following sections take a look at some more specialized animation techniques.
0262-01.jpg
Figure 9.10
Program Morph displaying transformation grids.

 
< previous page page_262 next page >